package com.explorati.interview.interview.chapterfive;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class SortTest {

	public static void main(String[] args) {
		List<Student> stuList = new ArrayList<Student>();
		stuList.add(new Student("stu001", 21));
		stuList.add(new Student("stu002", 29));
		stuList.add(new Student("stu003", 25));
		stuList.add(new Student("stu004", 23));
		System.out.println("---------------原顺序------------");
		for (Student stu : stuList) {
			System.out.println(stu);
		}

		System.out.println("---------------默认排序-------------");
		Collections.sort(stuList);
		for (Student stu : stuList) {
			System.out.println(stu);
		}

		System.out.println("----------------降序排列---------------");
		Comparator comp = Collections.reverseOrder();
		Collections.sort(stuList, comp);
		for (Student stu : stuList) {
			System.out.println(stu);
		}

		System.out.println("-----------------按名字重新排序-------------------");
		Collections.sort(stuList, new Comparator<Student>() {
			public int compare(Student stu1, Student stu2) {
				return stu1.getName().compareTo(stu2.getName());
			}
		});
		for (Student stu : stuList) {
			System.out.println(stu);
		}
	}
}
